package com.ruoyi.storage.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.storage.domain.ItemDetail;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.storage.domain.ProcessingRecord;
import com.ruoyi.storage.service.IProcessingRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 加工单管理Controller
 * 
 * @author 庞一恺
 * @date 2025-01-11
 */
@RestController
@RequestMapping("/storage/processRecord")
public class ProcessingRecordController extends BaseController
{
    @Autowired
    private IProcessingRecordService processingRecordService;

    /**
     * 查询加工单管理列表
     */
    @PreAuthorize("@ss.hasPermi('storage:processRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcessingRecord processingRecord)
    {
        startPage();
        processingRecord.setWarehouseId(SecurityUtils.getUserId());
        List<ProcessingRecord> list = processingRecordService.selectProcessingRecordList(processingRecord);
        return getDataTable(list);
    }

    /**
     * 导出加工单管理列表
     */
    @PreAuthorize("@ss.hasPermi('storage:processRecord:export')")
    @Log(title = "加工单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProcessingRecord processingRecord)
    {
        List<ProcessingRecord> list = processingRecordService.selectProcessingRecordList(processingRecord);
        ExcelUtil<ProcessingRecord> util = new ExcelUtil<ProcessingRecord>(ProcessingRecord.class);
        util.exportExcel(response, list, "加工单管理数据");
    }

    /**
     * 获取加工单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('storage:processRecord:query')")
    @GetMapping(value = "/{processId}")
    public AjaxResult getInfo(@PathVariable("processId") Long processId)
    {
        return success(processingRecordService.selectProcessingRecordByProcessId(processId));
    }

    /**
     * 新增加工单管理
     */
    @PreAuthorize("@ss.hasPermi('storage:processRecord:add')")
    @Log(title = "加工单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProcessingRecord processingRecord)
    {
        processingRecord.setWarehouseId(SecurityUtils.getUserId());
        return toAjax(processingRecordService.insertProcessingRecord(processingRecord));
    }

    /**
     * 修改加工单管理
     */
    @PreAuthorize("@ss.hasPermi('storage:processRecord:edit')")
    @Log(title = "加工单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProcessingRecord processingRecord)
    {
        return toAjax(processingRecordService.updateProcessingRecord(processingRecord));
    }

    /**
     * 删除加工单管理
     */
    @PreAuthorize("@ss.hasPermi('storage:processRecord:remove')")
    @Log(title = "加工单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{processIds}")
    public AjaxResult remove(@PathVariable Long[] processIds)
    {
        return toAjax(processingRecordService.deleteProcessingRecordByProcessIds(processIds));
    }

    /**
     * 入库修改库区库位
     */
    @PreAuthorize("@ss.hasPermi('storage:processRecord:edit')")
    @Log(title = "加工单管理", businessType = BusinessType.UPDATE)
    @PutMapping("/updateEntryDetail")
    public AjaxResult updateEntryDetail(@RequestBody List<ItemDetail> itemDetailList)
    {
        return toAjax(processingRecordService.updateEntryDetail(itemDetailList));
    }
}
